# -*- coding: utf-8 -*-
"""
微博的第三方登录.
这里只是熟悉流程。和测试。
集成的时候用的第三方的包
"""
__author__ = "shu2015626"


def get_auth_url():
    weibo_auth_url = "https://api.weibo.com/oauth2/authorize"
    redirect_uri = "http://47.92.87.172:8000/complete/weibo"
    client_id = "23799967"
    auth_url = weibo_auth_url + f"?client_id={client_id}&redirect_uri={redirect_uri}"
    print(auth_url)


def get_access_token(code):
    access_token_url = "https://api.weibo.com/oauth2/access_token"
    import requests
    res_dict = requests.post(access_token_url, data={
        "client_id": "fdsfsd",
        "client_secret": "sdfff",
        "grant_type": "authorization_code",
        "code": code,
        "redirect_uri": "http://47.92.87.172:8000/complete/weibo"
    })


def get_user_info(access_token, uid):
    weibo_user_url = "https://api.weibo.com/2/users/show.json"
    user_url = weibo_user_url + f"?access_token{access_token}&uid={uid}"
    print(user_url)


if __name__ == "__main__":
    get_auth_url()
    get_access_token("fdsssssssss")
    get_user_info(access_token="dssss", uid="fsdd")

